package com.example.my12306;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {
    EditText mEtUserName;
    EditText mEtPassword;
    Button mBtnLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mBtnLogin = (Button)findViewById(R.id.login);
        initView();
        initEvent();



    }

    private void initEvent() {
        mBtnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String userName = mEtUserName.getText().toString();
                String password = mEtPassword.getText().toString();

                if (userName.equals("admin")&& password.equals("123")){

                    Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                    startActivity(intent);
                }else {

                    Toast.makeText(LoginActivity.this,"用户输入错误",Toast.LENGTH_SHORT).show();

                }


            }
        });

    }

    private void initView() {
mEtUserName=findViewById(R.id.edtUsername);
mEtPassword=findViewById(R.id.edtPassword);
mBtnLogin=findViewById(R.id.login);


    }
}
